/*
 *	Copyright (c) 2009 Queensland University of Technology. All rights reserved.
 *	The QUT Bioinformatics Collection is open source software released under the 
 *	Microsoft Public License (Ms-PL): http://www.microsoft.com/opensource/licenses.mspx.
 */
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using QUT.Bio.SilverMap.ObjectModel;
using QUT.Bio.Util;

namespace QUT.Bio.SilverMap {
	/// <summary>
	/// A DataProvider presents a populated object model to the client application for display.
	/// </summary>
	
	abstract public class DataProvider {

		#region Constructor
		/// <summary>
		/// Initialise this data provider.
		/// </summary>
		/// <param name="overlay">A popup overlay that can be used to display messages in a portable manner.</param>

		public DataProvider ( PopupOverlay overlay ) {
			Overlay = overlay;
		} 
		#endregion
	
		#region Event: LoadComplete
		/// <summary>
		/// Event that should be fired by this data provider when the contents of the
		/// associated data collection has been completely replaced by a Load operation.
		/// <para>
		///		Use this to signal that a complete rethink of the display is needed in
		///		a visualization application.
		/// </para>
		/// </summary>

		public event Action<DataProvider> LoadComplete; 
		#endregion
		
		#region Event: CollectionModified
		/// <summary>
		/// Event fired by data producer to let consumers know that an incremental
		/// change has been made to the contents of the associated data collection.
		/// <para>
		///		This is intended to be used when small modifications to the display
		///		of a visualisation tool are required.
		/// </para>
		/// </summary>
		
		public event Action<DataProvider> CollectionModified;
		#endregion

		#region Property: IsInteractive
		/// <summary>
		/// Returns true iff this data provider can display a Load dialog 
		/// and interact with user.
		/// </summary>

		virtual public bool IsInteractive {
			get {
				return false;
			}
		} 
		#endregion

		#region Property: Name
		/// <summary>
		///	A readable name for this provider.
		///	<para>
		///		This is likely to become deprecated in future releases.
		/// </para>
		/// </summary>

		virtual public string Name {
			get {
				return String.Empty;
			}
		} 
		#endregion
		
		#region Property: SilverMapCollection
		/// <summary>
		/// Get a reference to the data collection managed by this data provider.
		/// </summary>

		abstract public IFeatureCollection FeatureCollection {
			get;
		} 
		#endregion		
	
		#region Property: Overlay
		/// <summary>
		/// Get a reference to a drawing surface capable of displaying popup windows.
		/// </summary>

		public PopupOverlay Overlay {
			get;
			private set;
		}
		#endregion
		
		#region Method: DisplayLoadDialog
		/// <summary>
		/// Display a custom Load dialog, which should subsequently take care of
		/// user interaction, form input validation etc.
		/// <para>
		///		The default implementation does nothing.
		/// </para>
		/// </summary>

		virtual public void DisplayLoadDialog () {} 
		#endregion

		#region Method: Initialise
		/// <summary>
		///	Called by the client during application startup, giving an opportunity to
		///	preload data etc.
		///	<para>
		///		The default implementation does nothing.
		/// </para>
		/// </summary>
		/// <param name="args">An Arguments collection.</param>

		virtual public void Initialise ( Arguments args ) {
		}
		#endregion

		#region Method SignalCollectionModified
		/// <summary>
		/// Notifies listeners that a an incremental change has occurred in the data collection.
		/// <para>
		///		This should hopefully trigger changes in the consumer that provide a continuous 
		///		experience to the end user..
		/// </para>
		/// </summary>

		public void SignalCollectionModified () {
			if ( CollectionModified != null ) {
				CollectionModified( this );
			}
		}
		#endregion

		#region Method SignalLoadComplete
		/// <summary>
		/// Notifies listeners that a new data collection has been loaded and is ready for use.
		/// <para>
		///		This should only be used to signal _successful_ loads.
		/// </para>
		/// </summary>

		public void SignalLoadComplete () {
			if ( LoadComplete != null ) {
				LoadComplete( this );
			}
		}
		#endregion
	}
}
